public var players : ArrayList;

function Start() {
	Application.runInBackground = true;
	Network.isMessageQueueRunning = false;
	players = new ArrayList();
}

class Player {
	var Nick : String;
	var Address: NetworkPlayer;
	var toggleOn: boolean;
}

@RPC 
function addPlayer(nick: String, address: NetworkPlayer) {
	var p : Player = new Player();
	p.Nick = nick;
	p.Address = address;
	p.toggleOn = false;
	players.Add(p);
	Debug.Log("Player "+nick+" NP: "+address);
}

function OnGUI() {
	for (var i=0; i < players.Count; i++) {
		players[i].toggleOn = GUI.Toggle(Rect(350, 100 + i*30, 100, 25), players[i].toggleOn, players[i].Nick);
	}
}

function OnServerInitialized() {
	var comp : ChatExercicioPrivado = GetComponent("ChatExercicioPrivado");
	networkView.RPC("addPlayer",RPCMode.AllBuffered, comp.nick, Network.player);
}

function OnConnectedToServer() {
	Debug.Log("Chamou");
	var comp : ChatExercicioPrivado = GetComponent("ChatExercicioPrivado");
	networkView.RPC("addPlayer",RPCMode.AllBuffered, comp.nick, Network.player);
}

@RPC
function removePlayer(np: NetworkPlayer) {
	for (var i=0; i<players.Count; i++) {
		if (players[i].Address == np) {
			players.Remove(players[i]);
			break;
		}
	}
}

function OnPlayerDisconnected(np: NetworkPlayer) {
	networkView.RPC("removePlayer",RPCMode.AllBuffered, np);
}